package cn.newstrength.qiyiming.step;

import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.TranResult;
import cn.newstrength.wtdf.plugin.util.SpringUtils;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.exception.PAIException;
import cn.newstrength.wtdf.web.mybatis.service.MapperService;
import cn.newstrength.wtdf.web.mybatis.service.impl.MapperServiceImpl;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;
//import cn.newstrength.wtdf.web.util.StepUtils;

import java.util.Map;

public class GetKeyInsertStep implements OperationStep {
    @Override
    public int excute(Operation oper) throws PAIException {
        DataContext context = oper.getContext();
        String resource = context.getResource();
        if(resource!=null&&!"".equals(resource)){
            MapperService mapperService = SpringUtils.getBean("mapperService", MapperServiceImpl.class);
            TranParams<Map<String,Object>> params = new TranParams<>();
            params.setResource(resource);
            params.setSummary("添加客户信息");
            params.setTranType("InsertStep");
            TranResult<Integer> tranResult = mapperService.count(params);
            oper.setTranStepSuccResult(tranResult);
            return 0;
        }else {
            oper.setTranStepResult(-1,"请设置Resource",null);
            return 1;
        }

    }

    @Override
    public int init(Map<String, String> param) {
        return 0;
    }
}
